package test.zj;

import java.util.*;

/**
 * @Description 已知一个int数组，输出所有升序子集
 * @Author Firenut
 * @Date 2023-08-19 23:38
 */
public class T1 {
    List<List<Integer>> ans = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);

        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if(!set.contains(nums[i])){
                set.add(nums[i]);
            }
        }



        dfs(nums, new ArrayList<>(), 0);
        return ans;
    }

    void dfs(int[] nums, List<Integer> temp, int index) {
        if (index >= nums.length) {
            ans.add(new ArrayList<>(temp));
            return;
        }

        // 选
        temp.add(nums[index]);
        dfs(nums, temp, index + 1);

        // 不选
        temp.remove(temp.size() - 1);
        dfs(nums, temp, index + 1);
    }
}
